﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushJScript.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>如何生成Url</h3>
    <b>1.通过Url函数生成</b><br />
    在控制器中。
    <pre class="brush:csharp;">
    public class IndexController
    {
        public ActionResult Index()
        {
            //string url=Url&lt;IndexController>("Index")
            string url=Url("Index");
            return Json();
        }
        public ActionResult News(int id)
        {
            int id=1;
            //string url=Url&lt;IndexController>("News",id);
            string url=Url("News",id);
            return View();
        }
    }
    </pre>
    <b>2.通过UrlHelper生成</b><br />
    2.1在Razor中生成
    <pre class="brush:xml;">
        @{
            string url=UrlHelper.GetUrl&lt;IndexController>("Index");
            url=UrlHelper.GetUrl&lt;IndexController>("News",id);
        }
    </pre>
    2.2在代码中生成
    <pre class="brush:xml;">
        public void Run()
        {
            NFinal.UrlHelper urlHelper=new NFinal.UrlHelper();
            string url=UrlHelper.GetUrl&lt;IndexController>("Index");
            url=UrlHelper.GetUrl&lt;IndexController>("News",id);
        }
    </pre>
    <b>3.通过Javascript生成</b><br />
    <pre class="brush:jscript">
    &lt;script src="/Scripts/Url.js">&lt;/script>
    &lt;script>
        var url = Url.IndexController.Index();
        var id = 1;
        url = Url.IndexController.News(id);
    &lt;/script>
    </pre>
</body>
</html>